package directory.controller;

import controller.*;
import java.sql.ResultSet;
import java.util.Vector;
import directory.model.PersonRelationship;

public class PersonRelationshipMgr extends DbManager {
    public static final PersonRelationshipMgr mgr = new PersonRelationshipMgr();
    
    private PersonRelationshipMgr() {
        super( "PersonRelationship" );
        m_titles = new String[]{ "RELACION", "PERSONA A", "PERSONA B", "DESDE", "HASTA" };
    }

    @Override
    protected PersonRelationship getBean() {
        return new PersonRelationship();
    }
    
    @Override
    public PersonRelationship getItem( String id ) {
        return (PersonRelationship) super.getItem( id );
    }
    
    @Override
    @SuppressWarnings("unchecked")
    protected void addObject( Vector v, ResultSet rs ) {
        v.add( new PersonRelationship( rs ) );
    }
    
    public synchronized Vector<PersonRelationship> getRelacionesActivasFromA( String idA ) {
        return executeQuery( "select * from PersonRelationship where idPersonA = " + idA + " and (dateTo is null or dateTo > '" + today() +"')" );
    }

    public synchronized Vector<PersonRelationship> getRelacionesInactivasFromA( String idA ) {
        return executeQuery( "select * from PersonRelationship where idPersonA = " + idA + " and (dateTo is not null and dateTo < '" + today() +"')" );
    }

    public synchronized Vector<PersonRelationship> getRelacionesActivasToB( String idB ) {
        return executeQuery( "select * from PersonRelationship where idPersonB = " + idB + " and (dateTo is null or dateTo > '" + today() +"')" );
    }

    public synchronized Vector<PersonRelationship> getRelacionesInactivasToB( String idB ) {
        return executeQuery( "select * from PersonRelationship where idPersonB = " + idB + " and (dateTo is not null and dateTo < '" + today() +"')" );
    }
}